home *** CD-ROM | disk | FTP | other *** search
- head 1.5;
- access;
- symbols;
- locks;
- comment @# @;
-
-
- 1.5
- date 99.10.08.18.15.35; author helios; state Exp;
- branches;
- next 1.4;
-
- 1.4
- date 99.10.08.17.35.31; author helios; state Exp;
- branches;
- next 1.3;
-
- 1.3
- date 99.09.29.12.23.22; author helios; state Exp;
- branches;
- next 1.2;
-
- 1.2
- date 99.09.29.12.15.27; author helios; state Exp;
- branches;
- next 1.1;
-
- 1.1
- date 99.09.29.10.47.55; author helios; state Exp;
- branches;
- next ;
-
-
- desc
- @PFSDefragTry Amiga E Source
- Tries to defragment files on a PFS volume using the
- PFS built-in defragment on overwrite feature.
- @
-
-
- 1.5
- log
- @- now I have it... hmmm... Stefan stored the pointers to the
- comment, the filedate and the protection bits to variables
- and freed the DosObject afterwards and then used them to
- restore the file data... this can't work or only works
- in the case when the freed structure has not been overwritten
- again
- AH this, sucked ;-)
- hopefully it really copies filenotes now... now keeps
- fib open till not used anymore
- - added some more comments to the source
- @
- text
- @/*
- PFSDefragTry
- $Id: PFSDefragTry.e 1.4 1999/10/08 17:35:31 helios Exp $
- */
-
- OPT OSVERSION=37
- OPT REG=5
-
- MODULE 'dos/dos'
- MODULE 'exec/memory'
-
- CONST MAXLINELEN=1000, BUFLEN=65536
- CONST TEMPFILELEN=100
-
- ENUM OK,ER_BADARGS,ER_DISKVALID,ER_DELETE,ER_COPYING,ER_EXAMINE,ER_PROT,ER_DATE,ER_COMMENT,ER_NOLOCK,BREAK
- ENUM ARG_DEVICE,ARG_TEMPDIR,ARG_BUFLEN,NUMARGS
-
- PROC delfile(file)
- DEF i
-
- i := DeleteFile(file)
- IF i = FALSE
- i := SetProtection(file, 0)
- IF i= TRUE
- i := DeleteFile(file)
- IF i = FALSE THEN PrintF('Deleting file "\s" failed!', file)
- ELSE
- PrintF('Removing delete protection from file "\s" failed!\n', file)
- ENDIF
- ENDIF
- ENDPROC i
-
- PROC copyfile(from=NIL,to=NIL,buffer=NIL,buflen=0)
- DEF ok=FALSE, ready=FALSE, readlen, writelen, fh_from=NIL, fh_to=NIL
-
- IF fh_from:=Open(from,MODE_OLDFILE)
- IF fh_to:=Open(to,MODE_NEWFILE)
- IF buffer
- IF buflen
- REPEAT
- readlen:=Read(fh_from, buffer, buflen)
- IF readlen<buflen THEN ready:=TRUE
- IF readlen<>TRUE
- IF readlen>0
- writelen:=Write(fh_to, buffer, readlen)
- ELSE
- writelen:=0
- ENDIF
- IF writelen<>readlen
- ready:=TRUE
- ELSE
- IF ready THEN ok:=TRUE
- ENDIF
- ENDIF
- UNTIL ready=TRUE
- ENDIF
- ENDIF
- Close(fh_to)
- ENDIF
- Close(fh_from)
- ENDIF
- ENDPROC ok
-
- PROC main() HANDLE
- DEF fh_fragfiles=NIL,i,s[MAXLINELEN]:STRING,file[MAXLINELEN]:STRING
- DEF rdargs=NIL, templ, args[NUMARGS]:LIST, buffer=NIL, buflen=BUFLEN
- DEF tempfile[TEMPFILELEN]:STRING
- DEF lock=NIL:LONG
- DEF fib=NIL:PTR TO fileinfoblock
- DEF examineok:LONG
-
- args:=[NIL,NIL,NIL]
-
- templ:='DEVICE/A,TEMPDIR,BUFLEN/N'; rdargs:=ReadArgs(templ,args,NIL)
- IF rdargs=NIL THEN Raise(ER_BADARGS)
-
- IF args[ARG_BUFLEN]
- buflen:=Long(args[ARG_BUFLEN])
- IF buflen<4096 THEN buflen:=4096
- ENDIF
-
- PrintF('Examing \s with DiskValid... ',args[ARG_DEVICE])
- Flush(stdout)
-
- StringF(s,'diskvalid \s analyse >RAM:fragfiles',args[ARG_DEVICE])
- i:=SystemTagList(s, NIL)
- IF i<>0
- PrintF('failed!\n')
- Raise(ER_DISKVALID)
- ENDIF
- PrintF('ok.\n')
-
- IF fh_fragfiles:=Open('RAM:fragfiles',MODE_OLDFILE)
-
- PrintF('Allocating io buffer... ')
- Flush(stdout)
- buffer:=AllocVec(buflen,MEMF_PUBLIC)
- IF buffer=NIL
- PrintF('failed!\n')
- Raise("MEM")
- ENDIF
- PrintF('ok.\n')
-
- IF args[ARG_TEMPDIR]
- tempfile:=args[ARG_TEMPDIR]
- ELSE
- tempfile:=args[ARG_DEVICE]
- ENDIF
-
- AddPart(tempfile,'---PFSDefragTry.tmp---',TEMPFILELEN)
-
- WHILE Fgets(fh_fragfiles,file,MAXLINELEN)
- SetStr(file,StrLen(file))
- IF StrCmp(file,'fragmented file',StrLen('fragmented file'))=TRUE
-
- MidStr(file,file,StrLen('fragmented file '))
- i:=InStr(file,' fragments')
- MidStr(file,file,0,i)
- REPEAT
- MidStr(file,file,0,StrLen(file)-1)
- RightStr(s,file,1)
- UNTIL StrCmp(s,'(')=TRUE
- MidStr(file,file,0,StrLen(file)-1)
- MidStr(file,file,0,StrLen(file)-1)
-
- PrintF('Trying to defragment "\s"... ',file)
- Flush(stdout)
-
- /* check for ctrl */
- IF CtrlC()
- PrintF('\n***Break\n')
- IF fh_fragfiles THEN Close(fh_fragfiles)
- CleanUp(10)
- ENDIF
-
- /* get file information */
- examineok := FALSE
- IF (lock := Lock(file, ACCESS_READ)) > 0
- fib := AllocDosObject(DOS_FIB, NIL)
- IF fib = 0
- Raise('MEM')
- ENDIF
- IF Examine(lock, fib)
- examineok := TRUE
- ELSE
- Raise(ER_EXAMINE)
- ENDIF
- UnLock(lock)
- ELSE
- Raise(ER_NOLOCK)
- ENDIF
-
- /* try to copy file to temporary place */
- i:=copyfile(file,tempfile,buffer,buflen)
- IF i = TRUE
- i:=delfile(file)
- IF i = FALSE
- Raise(ER_DELETE)
- ENDIF
-
- /* copy or rename the file back to original place */
- i:=Rename(tempfile,file)
- IF i=FALSE
- i:=copyfile(tempfile,file,buffer,buflen)
- IF i = TRUE
- delfile(tempfile)
- ELSE
- Raise(ER_COPYING)
- ENDIF
- ENDIF
-
- /* set protection */
- i := SetProtection(file,fib.protection)
- IF i = FALSE
- Raise(ER_PROT)
- ENDIF
-
- /* set file date */
- i := SetFileDate(file,fib.datestamp)
- IF i = FALSE
- Raise(ER_DATE)
- ENDIF
-
- /* set comment */
- i := SetComment(file,fib.comment)
- IF i = FALSE
- Raise(ER_COMMENT)
- ENDIF
- PrintF('ok.\n')
-
- IF fib
- FreeDosObject(DOS_FIB, fib)
- fib := 0
- ENDIF
-
- ELSE
- PrintF('failed!\n')
- delfile(tempfile)
- ENDIF
-
- ENDIF
- ENDWHILE
- ENDIF
- Raise(OK)
-
- EXCEPT
- SELECT exception
- CASE ER_BADARGS; PrintFault(IoErr(), 'PFSDefragTry')
- CASE ER_DISKVALID; PrintF('DiskValid failed!\n')
- PrintFault(IoErr(), 'PFSDefragTry')
- CASE ER_DELETE; PrintF('Could not delete "\s"!\n', file)
- PrintFault(IoErr(), 'PFSDefragTry')
- CASE ER_COPYING; PrintF('Could not copy temporary file "\s"!\n', tempfile)
- PrintFault(IoErr(), 'PFSDefragTry')
- CASE ER_EXAMINE; PrintF('Could not Examine() "\s"!', file)
- PrintFault(IoErr(), 'PFSDefragTry')
- CASE ER_PROT; PrintF('Could not set protection bits for "\s"!', file)
- PrintFault(IoErr(), 'PFSDefragTry')
- CASE ER_DATE; PrintF('Could not set file date for "\s"!', file)
- PrintFault(IoErr(), 'PFSDefragTry')
- CASE ER_COMMENT; PrintF('Could not set comment for "\s"!', file)
- PrintFault(IoErr(), 'PFSDefragTry')
- CASE ER_NOLOCK; PrintF('Could not lock file "\s"!', file)
- PrintFault(IoErr(), 'PFSDefragTry')
- CASE "MEM"; PrintF('Not enough memory!\n')
- DEFAULT; PrintFault(exception,'PFSDefragtry')
- ENDSELECT
-
- IF fib THEN FreeDosObject(DOS_FIB, fib)
- IF buffer THEN FreeVec(buffer)
- IF fh_fragfiles THEN Close(fh_fragfiles)
- IF rdargs THEN FreeArgs(rdargs)
-
- ENDPROC
- CHAR '$VER: PFSDefragTry 1.5 (8.10.1999)',0
-
- @
-
-
- 1.4
- log
- @- cosmetical changes, revised error messages
- - tried to find not setting filenote problem... this
- is strange. I could reproduce it when there was other
- activity on disc but after some changes it seemed to
- be gone
- - cause of that I added all error checking it can get
- when comment can not be set it should really complain
- now
- @
- text
- @d3 1
- a3 1
- $Id: PFSDefragTry.e 1.3 1999/09/29 12:23:22 helios Exp $
- d12 2
- a13 1
- CONST MAXLINELEN=2000, BUFLEN=65536
- d15 1
- a15 1
- ENUM OK,ER_BADARGS,ER_DISKVALID,ER_DELETE,ER_COPYING,ER_EXAMINE,ER_PROT,ER_DATE,ER_COMMENT,BREAK
- d67 1
- a67 1
- DEF tempfile[50]:STRING
- d70 1
- a70 3
- DEF protection=NIL:LONG
- DEF date:PTR TO datestamp
- DEF comment[200]:STRING
- d82 1
- a82 1
- PrintF('Examing \s with diskvalid... ',args[ARG_DEVICE])
- d110 1
- a110 1
- AddPart(tempfile,'---PFSDefragTry.tmp---',50)
- d129 1
- d136 2
- d140 3
- d144 1
- a144 5
- protection := fib.protection
- date := fib.datestamp
- comment := fib.comment
- FreeDosObject(DOS_FIB, fib)
- UnLock(lock)
- d146 1
- a146 1
- Raise(ER_EXAMINE)
- d148 3
- d153 1
- d161 1
- d173 1
- a173 1
- i := SetProtection(file,protection)
- d179 1
- a179 1
- i := SetFileDate(file,date)
- d185 3
- a187 6
- IF StrLen(comment) > 0
- PrintF('\nSetting comment\n')
- i := SetComment(file,comment)
- IF i = FALSE
- Raise(ER_COMMENT)
- ENDIF
- d191 5
- d221 3
- a223 1
- CASE ER_COMMENT; PrintF('Could not set comment "\s" for "\s"!', comment, file)
- d229 1
- d233 1
- d235 1
- a235 1
- CHAR '$VER: PFSDefragTry 1.4 (8.10.1999)',0
- @
-
-
- 1.3
- log
- @- changed some texts
- @
- text
- @d3 1
- a3 1
- $Id$
- d12 1
- a12 1
- CONST MAXLINELEN=1000, BUFLEN=65536
- d14 1
- a14 1
- ENUM OK,ER_BADARGS,ER_DISKVALID,ER_DELETE,ER_RENAMING,BREAK
- d20 6
- a25 6
- i:=DeleteFile(file)
- IF i=FALSE
- i:=SetProtection(file, 0)
- IF i=TRUE
- i:=DeleteFile(file)
- IF i=FALSE THEN PrintF('deleting file "\s" failed!', file)
- d27 1
- a27 1
- PrintF('removing delete protection from file "\s" failed!\n', file)
- a29 1
-
- a60 1
-
- d67 5
- a71 5
- DEF lock=NIL:LONG,
- fib=NIL:PTR TO fileinfoblock,
- protection=NIL:LONG,
- date:PTR TO datestamp,
- comment[200]:STRING
- d83 1
- a83 1
- PrintF('examing \s with diskvalid... ',args[ARG_DEVICE])
- d96 1
- a96 1
- PrintF('allocating io buffer... ')
- d127 1
- a127 1
- PrintF('trying to defragment "\s"... ',file)
- d136 13
- d150 4
- a153 10
- IF i=TRUE
- IF (lock := Lock(file, ACCESS_READ)) >0
- fib := AllocDosObject(DOS_FIB, NIL)
- IF Examine(lock, fib)
- protection := fib.protection
- date := fib.datestamp
- comment := fib.comment
- FreeDosObject(DOS_FIB, fib)
- UnLock(lock)
- ENDIF
- a154 2
- i:=delfile(file)
- IF i=FALSE THEN Raise(ER_DELETE)
- d159 1
- a159 1
- IF i:=TRUE
- d162 22
- a183 1
- Raise(ER_RENAMING)
- a185 3
- SetProtection(file,protection)
- SetFileDate(file,date)
- IF StrLen(comment) > 0 THEN SetComment(file,comment)
- d187 1
- d196 1
- a197 1
- Raise(OK)
- d200 1
- a200 1
- CASE ER_BADARGS; PrintF('PFSDefragTry (W) by Martin Steigerwald and Stefan Pucino\nBad arguments\n')
- d202 13
- a214 2
- CASE ER_DELETE; PrintF('Deleting file "\s" failed!\n',file)
- CASE ER_RENAMING; PrintF('Renaming temp file "\s" failed!\n',tempfile)
- d216 1
- a216 1
- DEFAULT; PrintFault(exception,'Error!\n')
- d223 1
- a223 1
- CHAR '$VER: PFSDefragTry 1.3 (29.9.1999)',0
- @
-
-
- 1.2
- log
- @- now under control of HWGRCS (Hel)
- - implemented CTRL-C check while copying (Max)
- - implemented support for filecomment, date and attributes (Max)
- - This tool is completely Y2K-free ;-)) (Max)
- @
- text
- @d178 1
- a178 1
- CASE ER_BADARGS; PrintF('PFSDefragTry 1.2 (29.9.1999)\nBad arguments\n')
- d190 1
- a190 1
- CHAR '$VER: PFSDefragTry 1.2 (29.9.1999)',0
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d2 2
- a3 2
- $VER: PFSDefragTry.e 37.4 (19.9.1999) (W) by Martin Steigerwald
- Placed in Public domain!
- d14 1
- a14 1
- ENUM OK,ER_BADARGS,ER_DISKVALID,ER_DELETE,ER_RENAMING
- d69 5
- d132 6
- d140 10
- d162 3
- d178 1
- a178 1
- CASE ER_BADARGS; PrintF('PFSDefragTry 37.4 (W) 17.9.1999 by Martin Steigerwald.\nBad arguments\n')
- a186 1
-
- d190 1
- a190 1
- CHAR '$VER: PFSDefragTry 37.4 (17.9.1999) (W) by Martin Steigerwald',0
- @
-